package com.wangwenjun.concurrency.chapter18;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 *
 * 多次调用 LockSupport.unpark 只有一次有用
 * unpark相当于资源数量设置为1,　可以多次调用，但和执行一次没有区别
 * TimeUnit.SECONDS.sleep的阻塞LockSupport.unpark(t)没用
 */
public class UseLockSupport {

    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                System.out.println("InterruptedException");
                throw new RuntimeException(e);
            }
            System.out.println("park");
            LockSupport.park();
            System.out.println("Im free");
        });
        t.start();
        LockSupport.unpark(t);
        TimeUnit.SECONDS.sleep(2);
    }

}
